package dataAccess;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;



import dataAccess.OrdenCanceladaDAO;

import bussinesObjetcs.OrdenCanceladaBean;

public class OrdenCanceladaDAO {
//	ConnectionDB connectionDB;
	private PreparedStatement consultaorden, insertaorden;
	private Connection connection;
	
	public OrdenCanceladaDAO(){
		
	}
	
	public OrdenCanceladaDAO(Connection  connection){
      this.connection = connection;
	}

	public Connection getConnection(){
		return connection;
	}
		
	public void setConnection(Connection connection){
	   this.connection = connection;
	}
	
	public ArrayList<OrdenCanceladaBean> getOrdenList() {	
		    ArrayList<OrdenCanceladaBean> ordencanceladaList = new ArrayList<OrdenCanceladaBean>();
		    try {
		    	consultaorden = connection.prepareStatement("SELECT * FROM files.orden WHERE status = 'cancelada'");	   
		         // obtain list of colegios
		         synchronized(consultaorden) {
		            ResultSet results = consultaorden.executeQuery();
		            // get rows data{
		            while (results.next()) {
		            	OrdenCanceladaBean orden = new OrdenCanceladaBean();
			           
			           orden.setIdorden(results.getString("idorden"));
			           orden.setFecha(results.getString("fecha"));
			           orden.setCosto(results.getString("costo"));
			           orden.setTurno(results.getString("turno"));
			           orden.setFormapago(results.getString("formapago"));
			           orden.setStatus(results.getString("status"));
			           
			           ordencanceladaList.add(orden);
		            }
		        }
		        consultaorden.close();
		    } catch(SQLException sqle){
				 System.out.println(sqle);
			}	   
		    return ordencanceladaList;
	   }


	public OrdenCanceladaBean searchOrden(String status) {	
		OrdenCanceladaBean orden = null;
		    try {
		         consultaorden = connection.prepareStatement("SELECT * FROM files.orden WHERE status = cancelada");	   
		         consultaorden.setString(9, status);
		         // obtain ordenes
		         synchronized(consultaorden) {
		            ResultSet results = consultaorden.executeQuery();
		            // get rows data{
			  		  
		            while (results.next()) {	            	
			           orden = new OrdenCanceladaBean();
			           
			           orden.setIdorden(results.getString("idorden"));
			           orden.setFecha(results.getString("fecha"));
			           orden.setCosto(results.getString("costo"));
			           orden.setTurno(results.getString("turno"));
			           orden.setFormapago(results.getString("formapago"));
			           orden.setStatus(results.getString("status"));
			           
		            }
		        }
		        consultaorden.close();
		    } catch(SQLException sqle){
				 System.out.println(sqle);
			}	   
		    return orden;
	   }
	 public void addOrden (OrdenCanceladaBean orden)  {
		 try {
		   insertaorden = connection.prepareStatement("INSERT INTO files.orden VALUES(?,?,?,?,?,?)");
		   synchronized(insertaorden) {
			   
			   
			   insertaorden.setString(1, orden.getIdorden());
	           insertaorden.setString(2, orden.getFecha());
	           insertaorden.setString(3, orden.getCosto());
	           insertaorden.setString(4, orden.getTurno());
	           insertaorden.setString(5, orden.getFormapago());
	           insertaorden.setString(6, orden.getStatus());
	          	           
	           insertaorden.executeUpdate();
		   }
		   insertaorden.close();
		 } catch(SQLException sqle){
			 System.out.println(sqle);
		 }
		   
	   }

}